﻿<!--#include file="isLogin.aspx"-->
<script language="vb" runat=server>
REM 18:32 2007-7-24
dim Msg,isImgLoaded,remotefileurl,ImgImportPath

function ImportImg(ByVal sHttpFilePath As String)
	'on error resume next
	dim tempStr,ReturnValue,fileExName,contentType,remoteFileSize,tempStr2

	dim RemoveFile as New WebNote.HttpImport()
	'RemoveFile.getRemoteFileInfo(sHttpFilePath)
	
	
	'contentType=RemoveFile.remoteFileType
	'remoteFileSize=RemoveFile.remoteFileSize

	'if CLng(remotefile_maxfilesize)<>0 and CLng(remoteFileSize)>CLng(remotefile_maxfilesize) then
	'	ImportImg=""
'		Msg="lang_tips_improtremotefile_lagerthanmaxsize"
'		RemoveFile=nothing
'		Exit function
'	end if

	dim mmArt as New WebNote.WebNote()
	
	if RemoveFile.LoadHTTPFile(sHttpFilePath) then
		if mmArt.CheckFileType(allow_upload_file_ext,RemoveFile.getFileExtensionName(sHttpFilePath)) then
    			if RemoveFile.MD(Server.MapPath(mmArt.DirectionPath)) then
    				ReturnValue=RemoveFile.SaveToFile(mmArt.DirectionPath & "/" & getAutoName() & "." & RemoveFile.getFileExtensionName(sHttpFilePath))
   			else
				ReturnValue=""
			end if
		else
			if mmArt.CheckFileType("image/gif,image/jpeg,image/png,image/tiff",contentType) then
				RemoveFile.MD(Server.MapPath(mmArt.DirectionPath))
				tempStr2=Split(contentType,"/")
				fileExName=tempStr2(Ubound(tempStr2))
			else
				fileExName="jpg"
			end if
			ReturnValue=RemoveFile.SaveToFile(mmArt.DirectionPath & "/" & getAutoName() & "." & fileExName)
		end if

	else
		ImportImg=""
	end if
	
	mmArt = Nothing
	RemoveFile=nothing
	
	if err.Description<>"" then
		Msg=err.Description
	else
		ImportImg=ReturnValue
	end if
end function

function getAutoName() as string
	dim a
	Randomize
	a=Now()
	getAutoName=Year(a) & Month(a) & day(a) & Minute(a) & hour(a) & second(a) & Int((99 * Rnd) + 1)
end function


Function ServerReturn(sReturnvalue,sReturnFileUrl,errdescription)
	With Response
		.clear()
		.ContentType = "text/xml"
		.Write("<?xml version=""1.0"" encoding=""UTF-8""?>" & vbcrlf)
		.Write("<root>")
		.Write("<returnvalue>" & Lcase(sReturnvalue) & "</returnvalue>")
		.Write("<fileurl>" & sReturnFileUrl & "</fileurl>")
		.Write("<errordescription>" & errdescription & "</errordescription>")
		.Write("</root>")
		.End
	End With
End Function

</script>
<%

remotefileurl=Request.Form("remotefileurl")

if remotefileurl<>"" then
	isImgLoaded=ImportImg(remotefileurl)
	ServerReturn(true,isImgLoaded,Msg)
else
	ServerReturn(false,"","argment is empty.")
end if
%>
